import { defineConfig } from 'vite'
import { resolve, join } from "path";
import vue from '@vitejs/plugin-vue'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'
import { visualizer } from 'rollup-plugin-visualizer'
function pathResolve(dir) {
  return resolve(__dirname, ".", dir);
}
export default defineConfig({
  base: "/dc-page-designer",
  plugins: [
    vue(),
    monacoEditorPlugin({}),
    visualizer({
      emitFile: false,
      filename: 'stats.html',
      open: false,
      sourcemap: true
    })
  ],
  resolve: {
    alias: {
      "@/package": pathResolve("package"),
    }
  },
  optimizeDeps: {
    include: ['axios'],
  },
  build: {
    outDir: "lib", //输出文件名称
    lib: {
      entry: join(__dirname, './package/index.js'), //指定组件编译入口文件
      name: 'dcPageDesigner',
      fileName: (format) => `index.${format}.js` // 打包后的文件名
    }, //库编译模式配置
    sourcemap: false,
    terserOptions: {
      compress: {
        //生产环境时移除console
        drop_console: true,
        drop_debugger: true,
      },
    },
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ["vue", "monaco-editor"],
      output: {
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        globals: {
          vue: "Vue",
        },
      },
    }, // rollup打包配置
  },
  css: {
    preprocessorOptions: {
      less: {
        math: "always", // 括号内才使用数学计算
        globalVars: {
          // 全局变量
          mainColor: "red",
        },
      },
    },
  },
})
